package com.handlers;

import com.MiniBasicRowProcessor;
import com.MiniResultSetHanlder;
import com.MiniRowProcessor;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MiniArrayHandler implements MiniResultSetHanlder<Object[]>{
    static final MiniRowProcessor DEFAULT_ROW_PROCESSOR = new MiniBasicRowProcessor();
    private static final Object[] EMPTY_ARRAY= new Object[0];
    private final MiniRowProcessor convert;

    public MiniArrayHandler(MiniRowProcessor convert) {
        super();
        this.convert = convert;
    }

    public MiniArrayHandler() {
        this(DEFAULT_ROW_PROCESSOR);
    }

    @Override
    public Object[] handle(ResultSet rs) throws SQLException {
        return rs.next() ? this.convert.toArray(rs) : EMPTY_ARRAY;
    }
}
